package io.gitee.thghh.dynamic.liquibase.liquibase;

import io.gitee.thghh.dynamic.liquibase.configuration.DynamicLiquibaseConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

/**
 * SpringLiquibase工厂
 *
 * @author pengzhikang
 * @date 2024/11/28 17:08
 * @since 1.0.0
 */
@Component
public class DynamicSpringLiquibaseFactory {

    @Autowired
    private ConfigurableListableBeanFactory beanFactory;

    /**
     * 获取动态liquibase对象
     *
     * @param liquibaseType 动态liquibase类型
     * @return {@link DynamicSpringLiquibase }
     * @author pengzhikang
     * @date 2024/11/28 17:11
     */
    public DynamicSpringLiquibase getSpringLiquibase(String liquibaseType) {
        String beanName = liquibaseType + DynamicLiquibaseConfiguration.SPRING_LIQUIBASE;
        if (beanFactory.containsBean(beanName)) {
            return beanFactory.getBean(beanName, DynamicSpringLiquibase.class);
        }
        return null;
    }

}
